package net.cmkj.mine.util;

import java.lang.reflect.Method;

public class BeanUtils {
	
	public static String compare(Object src, Object target) {
		Class<?> srcClass = src.getClass();
		Class<?> targetClass = target.getClass();
		StringBuffer sb = new StringBuffer(srcClass.getName()+"对象变动：");
		Method[] e1Method = srcClass.getMethods();
		Method[] e2Method = targetClass.getMethods();
		for (int i = 0; i < e1Method.length; i++) {
			Method e1F = e1Method[i];
			if(e1F.getName().startsWith("get") && e1F.toString().indexOf("Base") > -1 && e1F.toString().indexOf("BaseModel") < 0){
				Object o1;
				try{
					o1 = e1F.invoke(src);
				}catch(Exception e){
					continue;
				}
				for (int j = 0; j < e2Method.length; j++) {
					Method e2F = e2Method[j];
					if(e1F.getName().equals(e2F.getName())){
						Object o2;
						try{
							o2 = e1F.invoke(target);
						}catch(Exception e){
							continue;
						}
						if(o1 != null && !o1.equals(o2))
							sb.append(e1F.getName().replace("get", "") + "属性由'" +o1 + "'更新为'" + o2 + "',");
					}
				}
			}
		}
		return sb.toString();
	}

}
